package Homework;

public class Homework01 {

    public static void main(String[] args) {

        int[][] arr = new int[16][16];
        int num = 0;// 元素初始值
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                arr[i][j] = num++;
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
        for (int i = 0; i < arr.length; i++) {
            int sum1 = 0;// 每行之和
            int sum2 = 0;// 每列之和
            for (int j = 0; j < arr[i].length; j++) {
                sum1 += arr[i][j];
                sum2 += arr[j][i];
                }
                System.out.println("第" + (i + 1) + "行的元素总和为" + sum1 + ",第" + (i + 1) + "列的元素总和为" + sum2);
            }
        int sum3 = 0;// 左上到右下之和
        int sum4 = 0;// 右上到左下之和
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (i == j) {
                    sum3 += arr[i][j];
                }
                if ((i + j )== 16) {
                    sum4 += arr[i][j];
                }
            }
        }
        System.out.println("左上角到右下角的元素累加和为：" + sum3 + "，右上角到左下角的元素累加和为：" + sum4);
    }
}
